package com.woniu.springbootshiro.controller;


import com.woniu.springbootshiro.pojo.LampStrategy;
import com.woniu.springbootshiro.service.LampStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.ws.Action;
import java.util.List;

@Controller
public class LampStrategyController {
  @Autowired
  private LampStrategyService lampStrategyService;

  @RequestMapping("/queryAllLampStragegy")
  @ResponseBody
  public List<LampStrategy> queryAllLampStragegy() {
    return lampStrategyService.queryAllLampStragegy();
  }

  @RequestMapping("/delete")
  @ResponseBody
  public String deleteOne(Integer id) {

    int status = lampStrategyService.deleteOne(id);
    String status1 = String.valueOf(status);
    return status1;
  }

  @RequestMapping("/deleteAll")
  @ResponseBody
  public String deleteAll(String ids) {
    String[] idArr = ids.split(",");
    int temp = 0;
    for (int i = 0; i < idArr.length; i++) {
      temp = Integer.parseInt(idArr[i]);
      lampStrategyService.deleteOne(temp);
    }
    return "1";
  }

  @RequestMapping("/addStrategy")
  public void addStrategy(LampStrategy lampStrategy, HttpServletResponse resp) {
  int status = lampStrategyService.insertOne(lampStrategy);
  String sta = String.valueOf(status);

  }

  @RequestMapping("/updateStrategy")
  public void updateStrategy(LampStrategy lampStrategy, HttpServletResponse resp) {
    int status = lampStrategyService.updateStrategy(lampStrategy);
  }

  @RequestMapping("/queryStrategyById")
  @ResponseBody
  public LampStrategy queryStrategyById(HttpServletRequest req){
    String id=req.getParameter("id");
    System.out.println("id:"+id);
    Integer ids = Integer.parseInt(id);
    LampStrategy lampStrategy = lampStrategyService.queryStrategyById(ids);
    System.out.println(lampStrategy);
    return lampStrategy;
  }
}
